using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for NavigationStripControl
/// </summary>
namespace SqlWebAdmin.CSharp.Controls
{
    public class NavigationStripControl : System.Web.UI.HtmlControls.HtmlGenericControl
    {
        public NavigationStripControl()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        protected override void Render(HtmlTextWriter writer)
        {
            SiteMapNode rootNode = SiteMap.RootNode;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            if (rootNode != null)
            {
                foreach (SiteMapNode childNode in rootNode.ChildNodes)
                {
                    if (!String.IsNullOrEmpty(childNode["showAsTab"]))
                    {
                        sb.AppendFormat("<li {3}><a href=\"{0}\">{1}</a></li>" + Environment.NewLine, childNode.Url, childNode.Title, childNode == SiteMap.CurrentNode ? "id=\"current\"" : String.Empty );
                    }
                }

                if (sb.Length > 0)
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID );
                    writer.RenderBeginTag(HtmlTextWriterTag.Ul);
                    writer.WriteLine(sb.ToString());
                    writer.RenderEndTag();
                }
            }
        }
    }
}